require({
    paths: {
        templates: 'v/',
        Handlebars: 'libs/handlebars',
        text: 'libs/text',
        hbars: 'libs/hbars',
        jquery: 'libs/jquery',
        router: 'libs/router',
        x2js: 'libs/x2js'
    },
    shim: {
        Handlebars: {
            exports: 'Handlebars'
        }
    },
    onBuildWrite: function(moduleName, path, content) {
        //替换所有handlebars.js为handlebars.runtime.js，并读取数据。
        if (moduleName === 'Handlebars') {
            path = path.replace('handlebars.js', 'handlebars.runtime.js');
            content = fs.readFileSync(path).toString();
            content = content.replace(/(define\()(function)/, '$1"handlebars", $2');
        }
        return content;
    }

}, ['router', 'config'], function(router, config) {
    'use strict';
    //配置路由
    router
        .registerRoutes(config)
        .on('routeload', function(module, routeArguments) {
            new module(routeArguments);
        })
        .go();
});